<?php

require_once "core/controller.class.php";
require_once "plugins/auth_plugin.php";


class IndexController extends Controller
{
/*{{{ login */
    public function login ($params) {

        $this->render("index/login.tpl");
    }

    public function login_action ($params) {
        $request = $this->request();
        $response = $this->response();
        $user_name = $request->getVar('username', 'post');
        $password = $request->getVar('password', 'post');
        if (empty($user_name) or empty($password)) {
            $response->appendErrMsg("username or password cannot be empty.");
            $this->login($params);
            return;
        }

        if (!AuthSimpleUser::login($user_name, $password)) {
            $response->appendErrMsg("wrong password.");
            $this->login($params);
            return;
        } 

        $response->redirect('/');

    }

/*}}}*/

/*{{{ logout */
    public function logout ($params) {
        AuthSimpleUser::logout();
        $this->login($params);
    }

/*}}}*/


}




